package com.service.impl;

import com.dao.ThreeLinkRepository;
import com.entity.ThreeLink;
import com.service.ThreeLinkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ThreeLinkServiceImpl implements ThreeLinkService {

    @Autowired
    private ThreeLinkRepository threeLinkRepository;

    @Override
    public List<ThreeLink> findAll() {
        List<ThreeLink> list1 = threeLinkRepository.findAllByTypeAndPId(1, 1);
        for(ThreeLink threeLink:list1){
            List<ThreeLink> list2 = threeLinkRepository.findAllByTypeAndPId(2, threeLink.getId());
            threeLink.setThreeLinks(list2);
            for(ThreeLink threeLink1:list2){
                Integer id = threeLink1.getId();
                List<ThreeLink> list3 = threeLinkRepository.findAllByTypeAndPId(3, threeLink1.getId());
                threeLink1.setThreeLinks(list3);
            }
        }
        return list1;
    }

    /**
     * 通过省份ID查询市级信息
     * @param id
     * @return
     */
    @Override
    public List<ThreeLink> findAllCityByPid(Integer id) {
        List<ThreeLink> cityList = threeLinkRepository.findCityByPid(2, id);
        return cityList;
    }

    @Override
    public List<ThreeLink> findAllAreaByCid(Integer id) {
        List<ThreeLink> areaList = threeLinkRepository.findAreaByPid(3, id);
        return areaList;
    }

    @Override
    public String findAllNameById(Integer pro, Integer city, Integer area, String address_detail) {
        String pro_name=threeLinkRepository.findNameById(pro);
        String city_name=threeLinkRepository.findNameById(city);
        String area_name=threeLinkRepository.findNameById(area);
        String allAddress=pro_name+city_name+area_name+address_detail;
        return allAddress;
    }
}
